//
//  ForumView.m
//  LStyle
//
//  Created by Obaid Abdul Maroof on 12/16/09.
//  Copyright 2009 Vrije University. All rights reserved.
//

#import "ForumView.h"


@implementation ForumView

/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
	self.createFooter;
	tcAbout = [[UITabBar alloc] initWithFrame:CGRectMake(0, 480-50, 320, 30)];
	tvForum.separatorStyle = UITableViewCellSeparatorStyleNone;
	[tcAbout addSubview:strComent];
	[tcAbout addSubview:strNum];
	[tcAbout addSubview:lblBack];
	[tcAbout addSubview:lblForward];
	
	[self.view addSubview:tcAbout];
	
	currentView = subView;
	lblCurrent = strComent;
}


- (void)viewWillAppear:(BOOL)animated
{
	self.navigationController.navigationBarHidden = YES;
}


-(void) createFooter{
	UIFont *fnt = [UIFont fontWithName:@"Verdana" size: 10.0];
	strComent = [[UILabel alloc] initWithFrame:CGRectMake(15, 5, 60, 20)];
	strNum = [[UILabel alloc] initWithFrame:CGRectMake(80, 5, 60, 20)];
	lblBack = [[UILabel alloc] initWithFrame:CGRectMake(145, 5, 70, 20)];
	lblForward = [[UILabel alloc] initWithFrame:CGRectMake(220, 5, 80, 20)];
	
	strComent.textAlignment = UITextAlignmentCenter;
	strNum.textAlignment = UITextAlignmentCenter;
	lblBack.textAlignment = UITextAlignmentCenter;
	lblForward.textAlignment = UITextAlignmentCenter;
	
	[strComent setBackgroundColor:[UIColor darkGrayColor]];
	[strNum setBackgroundColor:[UIColor clearColor]];
	[lblForward setBackgroundColor:[UIColor clearColor]];
	[lblBack setBackgroundColor:[UIColor clearColor]]; 
	
	strComent.text = @"Latest";
	strNum.text = @"Answers";
	lblBack.text = @"My Threads";
	lblForward.text = @"Create Thread";
	
	strComent.font = fnt;
	strNum.font = fnt;
	lblForward.font = fnt;
	lblBack.font = fnt;
	
	strComent.textColor = [UIColor whiteColor];	
	strNum.textColor = [UIColor whiteColor];	
	lblBack.textColor = [UIColor whiteColor];		
	lblForward.textColor = [UIColor whiteColor];	
	
	strComent.userInteractionEnabled = YES;
	strNum.userInteractionEnabled = YES;
	lblBack.userInteractionEnabled = YES;
	lblForward.userInteractionEnabled = YES;
}


-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
	NSSet *allTouches = [event allTouches];
	
	UITouch *touch = [[allTouches allObjects] objectAtIndex:0];
	
	if (touch.view == strNum && lblCurrent != strNum){
		vcThreadView = [[ThreadView alloc] initWithNibName:@"ThreadView" bundle:[NSBundle mainBundle]];
		[lblCurrent setBackgroundColor:[UIColor clearColor]];
		lblCurrent = strNum;
		[lblCurrent setBackgroundColor:[UIColor darkGrayColor]];
		currentView = vcThreadView.view;
		
		CGRect rect = subView.frame;
		subView.hidden = TRUE;
		vcThreadView.view.frame = rect;
		
		[self.view addSubview:vcThreadView.view];
	}
	
	if (touch.view == lblBack && lblCurrent != lblBack){
		vcThreadView = [[ThreadView alloc] initWithNibName:@"ThreadView" bundle:[NSBundle mainBundle]];
		[lblCurrent setBackgroundColor:[UIColor clearColor]];
		lblCurrent = lblBack;
		[lblCurrent setBackgroundColor:[UIColor darkGrayColor]];
		
		CGRect rect = subView.frame;
		subView.hidden = TRUE;
		vcThreadView.view.frame = rect;
		
		[self.view addSubview:vcThreadView.view];
	}

	if (touch.view == lblForward && lblCurrent != lblForward){
		vcThreadView = [[ThreadView alloc] initWithNibName:@"ThreadView" bundle:[NSBundle mainBundle]];
		[lblCurrent setBackgroundColor:[UIColor clearColor]];
		lblCurrent = lblForward;
		[lblCurrent setBackgroundColor:[UIColor darkGrayColor]];
		
		CGRect rect = subView.frame;
		subView.hidden = TRUE;
		vcThreadView.view.frame = rect;
		
		[self.view addSubview:vcThreadView.view];
	}

	if (touch.view == strComent && lblCurrent != strComent){
		
		currentView.hidden = TRUE;
		[lblCurrent setBackgroundColor:[UIColor clearColor]];
		lblCurrent = strComent;
		[lblCurrent setBackgroundColor:[UIColor darkGrayColor]];
		
		subView.hidden = FALSE;
		currentView = subView;
				
		
	}
	
}


/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}


#pragma mark UITableView Delegate mehods

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
	return 5;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
	return 100;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
	int row = indexPath.row;
	UITableViewCell *cell = [tvForum dequeueReusableCellWithIdentifier:@"cell"];
	if (cell == nil)
	{
		cell = [[[ForumCellView alloc] initWithFrame:CGRectZero reuseIdentifier:@"cell"] autorelease];		
	}		
	return cell;
}

-(void)Back:(id)sender{
	[self.navigationController popViewControllerAnimated:YES];
}


@end
